MAX_RANGE = int(1e9 + 7)

class RangeModule:

    def __init__(self):
        self.tr = Tree()

    def addRange(self, left: int, right: int) -> None:
        Tree.update(self.tr.root, 1, MAX_RANGE, left, right - 1, True)  # 左闭右开区间

    def queryRange(self, left: int, right: int) -> bool:
        return Tree.query(self.tr.root, 1, MAX_RANGE, left, right - 1)

    def removeRange(self, left: int, right: int) -> None:
        Tree.update(self.tr.root, 1, MAX_RANGE, left, right - 1, False)

class Node:
    def __init__(self) -> None:
        self.lt = self.rt = None  # 左子树，右子树
        self.flag = self.add = False  # 当前结点的是否被覆盖和懒标记

class Tree:
    def __init__(self):
        self.root = Node()  # 初始化根节点

    @staticmethod
    def pushup(node: Node) -> None:  # 合并操作，根节点区间是否在区间内根据其两个子节点区间决定
        node.flag = node.lt.flag and node.rt.flag

    @staticmethod
    def pushdown(node: Node) -> None:  # 下放操作
        if node.lt is None:  # 动态开点，只有当用到了这些点时，才开辟空间
            node.lt = Node()
        if node.rt is None:
            node.rt = Node()
        if not node.add:  # 懒标记为false，不用下放
            return
        node.lt.flag, node.rt.flag = node.flag, node.flag  # 下放操作，子节点区间是否存在更新为父节点是否存在的标记flag
        node.lt.add, node.rt.add = True, True  # 下放操作，子节点的懒标记更新为父节点的懒标记
        node.add = False

    @staticmethod
    def update(node: Node, lc: int, rc: int, l: int, r: int, flag: bool) -> None:
        # 全覆盖
        if l <= lc and r >= rc:
            node.flag = flag
            # 一旦产生了变化懒标记就变为True，需要往下面继续更新
            node.add = True
            return
        Tree.pushdown(node)
        mid = lc + rc >> 1
        if l <= mid:
            Tree.update(node.lt, lc, mid, l, r, flag)
        if r > mid:
            Tree.update(node.rt, mid + 1, rc, l, r, flag)
        Tree.pushup(node)

    @staticmethod
    def query(node: Node, lc: int, rc: int, l: int, r: int) -> bool:
        if l <= lc and r >= rc:
            return node.flag
        # 下放当前结点
        Tree.pushdown(node)
        mid = lc + rc >> 1
        ans = True
        if l <= mid:
            ans = ans and Tree.query(node.lt, lc, mid, l, r)
        if r > mid:
            ans = ans and Tree.query(node.rt, mid + 1, rc, l, r)
        return ans